package org.metasketch.editor.perspectives;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimplePerspectiveManager {
	List<String> names = new ArrayList<String>();
	List<Perspective> perspectives = new ArrayList<Perspective>();
	Map<String, Perspective> perspectivePerName = new HashMap<String, Perspective>();
	String defaultPerspective;

	public String getDefaultPerspective() {
		return defaultPerspective;
	}

	public void setDefault(Perspective perspective) {
		defaultPerspective = perspective.getName();
		register(perspective);
	}

	public void register(Perspective perspective) {
		String name = perspective.getName();
		if (names.contains(name))
			throw new RuntimeException("Duplicated Diagram Type " + name);

		perspectives.add(perspective);
		names.add(name);
		perspectivePerName.put(name, perspective);
	}

	public Perspective getPerspective(String name) {
		return perspectivePerName.get(name);
	}

	public ILayout getLayout(String name) {
		return perspectivePerName.get(name).getLayout();
	}

	public List<String> getNames() {
		return names;
	}

}
